home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / contrib / zelk / include / theusual.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-13  |  8.7 KB  |  295 lines

  1. /* theusual.h
  2.  *
  3.  * Recommendations:
  4.  *- declare char,short,float args to functions as types Dchar,Dshort,Dfloat
  5.  *- typedef Dchar/Dshort/Dfloat as int,double.  declaring args as chars
  6.  *  does not add to efficiency; declaring args as floats rather than
  7.  *  doubles is dangerous (see below)-only do this in inner loops.
  8.  *- function which takes, returns void: Zvoid foo(Zvoid)
  9.  *- unspec: Zunspec
  10.  *- introduce new types as Ztype_t 
  11.  *
  12.  * Ansi strategy:
  13.  * SGI Ansi will pass float as float only if the function is DEFINED
  14.  *   using the new parameter-list style.  This style wont compile in k&r,
  15.  *   while the new PROTOTYPES can be desguised as k&r thru Zproto(()).
  16.  *   Also, passing float/char/short arguments without eleveation is
  17.  *   dangerous - all invokers must have access to the correct prototype.
  18.  *   Lastly, elk cannot identify a function which is really expecting
  19.  *   floats, vs. one which expects floats cast to doubles.
  20.  *   So, keep using old definitions, but new declarations - Sgi will
  21.  *   do old elevations but do type checking on these.
  22.  *  Unless a highly critical function...
  23.  *
  24.  *  I.E., use floats in calling sequence only in local functions WITHIN
  25.  *  a file.  all externally visible functions should be double.
  26.  *  C.F. Dfloat.
  27.  *  Thus, a declaration for a float foo(float) will be Dfloat foo(Dfloat)
  28.  *  (The return value would be ok as float, except for elk)
  29.  *
  30.  * note irix ansi cpp defines __ANSI_CPP__
  31.  *
  32.  * modified
  33.  * 11nov        improvements for gcc
  34.  * 30jun    U_int/etc
  35.  * 20june       include stdlib on sun
  36.  * 9apr         Zconst,zprototypes.h
  37.  * 7apr         Zunspec
  38.  * 24mar        sgi4d
  39.  * 30oct        Dfloat,Dint
  40.  * (mac mpw)
  41.  */
  42.  
  43. #ifndef THEUSUAL_H
  44. #define THEUSUAL_H
  45.  
  46. /* all important environment init */
  47. #define Einit()    
  48. #define Efinit()
  49.  
  50. /* environment config */
  51.  
  52. /* gcc understands void, prototypes,
  53.  * also has stdarg, Eansiincludes on its default -I path unless reset.
  54.  * Warning - gcc defs for exit,abort are different than in sun stdlib.h.
  55.  * Beware of the -ansi flag: standard defines such as sparc,unix,etc.
  56.  * are not provided, but __sparc__,etc. are.
  57.  */
  58. #ifdef __GNUC__
  59. # define Egcc           1
  60. # ifdef __STDC__
  61. #  define Eansi         1
  62. # else
  63. #  define Eansi         0
  64. # endif
  65. # define Eansiproto     1
  66. # define proc void
  67. # define Estdarg        1
  68. # define Evarargs       0
  69. # define Eansiincludes  1
  70. # define Eunix        1
  71. /* sparc,unix,etc. are not defined if -ansi flag is given,
  72.  * but gcc defines __sparc__,etc. */
  73. # if __sparc__
  74. #  define Esparc        1
  75. # endif /*sparc*/
  76.   /* UGH: exit and abort have conflicting definitions on the sun;
  77.      must get rid of the stdlib.h declarations if compiling mixed cc/gcc
  78.      */
  79. #  define exit junk1
  80. #  define abort junk2
  81. #   include <stdlib.h>
  82. #  undef exit
  83. #  undef abort
  84. #endif /*GNUC*/
  85.  
  86.  
  87. #if (sparc || Esparc)
  88. # define Esparc         1
  89. # define Eunix        1
  90. # define Ebsd        1
  91. # define Esys5sm        1       /* sysv style shared memory */
  92. # define Evaxorder    0
  93. # define E68Korder     1
  94. # if !__GNUC__
  95. #   define Evarargs       1
  96. #   define Estdarg        0
  97. #   define Eansiincludes  0
  98. # endif
  99. # define Evprintf    1    /* has vprintf() routines */
  100. # define Ebinarystream  0       /* has fopen(path,"wb" */
  101. # define EfloatC(f)    (float)f
  102.   /* the most efficient float type */
  103.   typedef float Efloat;
  104.   /* variable precision code should still use Flotype. rename Eflotype? */
  105.   /* gcc (and ANSI?) want prototypes to be declared as the type they
  106.    * elevate to, e.g. chars must be declared as ints, floats as doubles
  107.    * in the prototype ONLY (can be declared as char/float in the function).
  108.    * I think SGI compiler can deal with float prototypes.
  109.    * D* typedefs preserve information, used in arguments in prototypes.
  110.    * But not in return values.
  111.    */
  112.   typedef double Dfloat;
  113.   typedef int Dchar;
  114.   typedef int Dshort;
  115. # define Efltconst     0    /* allows 0.0F? now obsolete-use EfloatC() */
  116. # define Emulticconst    0
  117.   /* do NOT include stdlib.h: it is incorrect e.g. exit(),
  118.      and w/o prototypes it does not help much anyway */
  119.   /*#  include <stdlib.h>*/
  120. #endif /*sparc*/
  121.  
  122.  
  123. #if (SgiAnsi || ((mips || __mips__) && (__STDC__ || __EXTENSIONS__)))
  124. # define SgiAnsi        1
  125. # define Emips          1
  126. # define Esgi           1
  127. # define Evarargs    0    /* has varargs.h */
  128. # define Estdarg        1    /* has ansi stdarg.h */
  129. # define Eansiincludes  1       /* has stdlib.h, etc. */
  130. # define Evprintf    1    /* has vprintf() routines */
  131. # define Eansi        1
  132. # define Eansiproto    1
  133. # define Eansistring    1    /* has "" "" string concat, vs backslash */
  134. # define Ebinarystream  1       /* ? fopen(path,"rb") */
  135. # define EfloatC(x)    x ## f
  136.   /* the most efficient float type */
  137.   typedef float Efloat;
  138.   /* variable precision code should still use Flotype. rename Eflotype? */
  139.   /* gcc (and ANSI?) want prototypes to be declared as the type they
  140.    * elevate to, e.g. chars must be declared as ints, floats as doubles
  141.    * in the prototype ONLY (can be declared as char/float in the function).
  142.    * SGI compiler can deal with float prototypes, but elk cannot!
  143.    * all-around safer to use old c-style argument promotion Except
  144.    * in the innermost of loops.
  145.    * D* typedefs preserve information, used in prototypes.   */
  146.   typedef double Dfloat;
  147.   typedef int Dchar;
  148.   typedef int Dshort;
  149.  
  150. # define Eunix        1
  151. # define Ebsd        0   /* should ? */
  152. # define EsysV          1
  153. # define Eiris        1
  154. # define Esys5sm        1       /* sysv style shared memory */
  155. # define Efltconst     0    /* allows 0.0F? now obsolete-use EfloatC() */
  156. # define Emulticconst    0
  157. # define Evaxorder    0       /* not sure */
  158. # define E68Korder     1
  159. # include <stdlib.h>
  160. # include <string.h>
  161. # include <unistd.h>
  162. #endif /*SgiAnsi*/
  163.  
  164.  
  165. #if (mips && !SgiAnsi)
  166. # define Emips          1
  167. # define Esgi           1
  168. # define Evarargs    1    /* has varargs.h */
  169. # define Estdarg        0    /* has ansi stdarg.h */
  170. # define Eansiincludes  0       /* has stdlib.h, etc. */
  171. # define Evprintf    1    /* has vprintf() routines */
  172. # define Eansi        0
  173. # define Eansiproto    1
  174. # define Eansistring    0    /* has "" "" string concat, vs backslash */
  175. # define Ebinarystream  1       
  176. # define EfloatC(f)    (float)(f)
  177.   /* the most efficient float type */
  178.   typedef float Efloat;
  179.   /* variable precision code should still use Flotype. rename  Eflotype? */
  180.   /* gcc (and ANSI?) want prototypes to be declared as the type they
  181.    * elevate to, e.g. chars must be declared as ints, floats as doubles
  182.    * in the prototype ONLY (can be declared as char/float in the function).
  183.    * I think SGI compiler can deal with float prototypes.
  184.    * D* typedefs preserve information, used in prototypes.
  185.    */
  186.   typedef double Dfloat;
  187.   typedef int Dchar;
  188.   typedef int Dshort;
  189. # define Eunix        1
  190. # define Ebsd        0   /* should ? */
  191. # define EsysV          1
  192. # define Eiris        1
  193. # define Esys5sm        1       /* sysv style shared memory */
  194. # define Efltconst     0    /* allows 0.0F? now obsolete-use EfloatC() */
  195. # define Emulticconst    0
  196. # define Evaxorder    0
  197. # define E68Korder     1
  198. #endif /*mips*/
  199.  
  200. /**** types ****/
  201. #if Eansi
  202.   typedef void *UNSPEC;
  203.   typedef void *Zunspec;        /* use Zvoid as returnvalue, Zunspec */
  204.                                 /* in functions */
  205. # define proc void
  206. # define Zvoid void
  207. # define Zconst const
  208.   typedef void (vfunction)();   /* pointer to procedure */
  209. #else
  210.   typedef char *UNSPEC;
  211.   typedef char *Zunspec;
  212. # define proc
  213. # define Zvoid
  214. # define Zconst
  215.   typedef int (vfunction)();
  216. #endif
  217. /* types.h is in sys/ on some systems, not on others */
  218. typedef unsigned int U_int;
  219. typedef unsigned short U_short;
  220. typedef unsigned char U_char;
  221.  
  222. /* allow both new, old style function definitions. must declare
  223.         int f(int a,float b)
  224.    as
  225.         int ZDECLARE2(f,int,a,float,b)
  226.  */
  227. #include <zprototypes.h>
  228.  
  229. #if Eansiproto
  230. # define Zproto(x) x
  231. #else
  232. # define Zproto(x) ()
  233. #endif
  234.  
  235. #if (Emc68020|Esparc|Emips|(Emac&&Empw))
  236. # define int4 int
  237. # define int2 short
  238. # define bool4 int
  239. #endif
  240. #if (Emac&&Elsc)
  241. # define int4 long
  242. # define int2 int
  243. # define bool4 long
  244. #endif
  245. # ifndef int4
  246. :error
  247. #endif
  248.  
  249. /* existing code uses some of these names, e.g. TRUE, byte, proc.
  250.  * could z* to avoid conflicts.  tried this, looked ugly.
  251.  * easier to just #undef these in conflicting cases.
  252.  */
  253. #define FALSE 0
  254. #define TRUE  1
  255. #define bool int
  256. #define global
  257. #define forward
  258. #define local static
  259. typedef int4 (function)();
  260. typedef char *Zaddr;
  261. typedef unsigned char Zbyte;
  262.  
  263. #if Enoalloc
  264. # define Memalloc(n) malloc(n)
  265. # define Memfree(a)  free(a)
  266. #else
  267. # define Memalloc(n) alloca(n)
  268. # define Memfree(a)
  269. #endif
  270.  
  271. #define Zmultichar(a,b,c,d) (unsigned long)(((a)<<24)|((b)<<16)|((c)<<8)|(d)) 
  272.  
  273. #ifdef ztrace
  274. #    define Ztrace(x)    printf x
  275. #else
  276. #    define Ztrace(x)
  277. #endif
  278. #ifdef ztrace2
  279. #    define Ztrace2(x)   printf x
  280. #else
  281. #    define Ztrace2(x)
  282. #endif
  283.  
  284. #include <math.h>
  285.  
  286. #ifndef EOF
  287. # include <stdio.h>
  288. #endif
  289.  
  290. #include <libz.h>
  291.  
  292. #define VERALIGN(ptr,n) assert(((((int4)ptr)/n)*n)==n)
  293.  
  294. #endif /*THEUSUAL_H*/
  295.